<?php

/*
 *
 * Template Name: credit
 *
 */
	 
?>

<!doctype html>
<html dir="ltr" lang="en-US">
	<?php get_header('head'); ?>
	<body>
		<?php get_header('nav') ?>
				
		<section id="category_posts">
			<?php
				// get all "author" and "photographer" custom field records and
				// store in array sort alphabetically so that comparison works
				$all_pairs = $wpdb->get_results(
					"SELECT post_id, meta_value 
					 FROM wp_postmeta 
					 WHERE meta_key = 'author' OR meta_key = 'photographer' OR  meta_key = 'photographers'
					 ORDER BY meta_value", 
					ARRAY_A);
					
				$authors = sort_authors($all_pairs);
								
				// display each author, but not their posts (too time consuming to display all
				// at once - need to use ajax to display them selectively
				foreach ($authors as $author => $posts) {
					$random_id = rand();
					echo '<div id="a_'.$random_id.'" class="query row"><p class="twelvecol last">'.$author.' &ndash; <a href="javascript:get_articles(\''.$author.'\', '.$random_id.');">show articles</a></p></div>';
					/*
					foreach ($author_array['posts'] as $post_id) {
						query_posts("p=$post_id");
						while (have_posts()) : the_post();
							echo '<div class="post row" id="', the_ID(), '">';
							category_preview();
							echo '</div>';
						endwhile;
						wp_reset_query();
					}
					*/
				}
			?>
		</section>
		
		<script type="text/javascript" src="<?php bloginfo('template_directory') ?>/js/author_posts.js"></script>
		
		<?php get_footer();?>
	</body>
</html>
